package auth

import (
	"time"
	"github.com/astaxie/beego/orm"
)

//用户表
type User struct {
     Id int `orm:"pk;auto"`
     UserName string `orm:"unique;column(username);size(30);description(用户账号)"`
	 TrueName string `orm:"unique;column(truename);size(60);description(真实姓名)"`
     Password string `orm:"size(32);description(用户密码)"`
     Age int `orm:"null;description(年龄)"`
     Gender int `orm:"null;description(性别)"`
     Phone int64 `orm:"null;description(手机号)"`
	 Email string `orm:"size(120);null;description(邮箱)"`
     Address string `orm:"null;description(地址)"`
	 Mark string `orm:"null;description(备注)"`
     IsActive int `orm:"default(1);description(1启用，0停用)"`
     IsDelete int `orm:"default(0);description(1删除，0未删除)"`
     CreateTime time.Time `orm:"auto_now;type(datetime);description(创建时间);null"`
	 Role []*Role `orm:"reverse(many)"`
}

//角色
type Role struct {
	Id int `orm:"pk;auto"`
	RoleName string `orm:"size(64);description(角色名称)"`
	Desc string `orm:"size(255);description(备注)"`
	IsActive int `orm:"column(is_active);description(1启用，0停用)"`
	IsDelete int `orm:"column(is_delete);description(1删除，0未删除)"`
	CreateTime time.Time `orm:"type(datetime);auto_now;description(创建时间)"`
	User []*User `orm:"rel(m2m)"`
	Auth []*Auth `orm:"rel(m2m)"`
}

type Auth struct {
	Id int `orm:"pk;auto"`
	AuthName string	`orm:"description(权限名称);size(64)"`
	UrlFor string	`orm:"description(url反转);size(255)"`
	Pid int	`orm:"description(父节点id)"`
	Desc string	`orm:"description(描述);size(255)"`
	CreateTime time.Time `orm:"type(datetime);auto_now;description(创建时间)"`
	IsActive int `orm:"column(is_active);description(1启用，0停用)"`
	IsDelete int `orm:"columns(is_delete);description(1删除，0未删除)"`
	Weight int	`orm:"description(权重，数值越大，权重越大)"`
	Role []*Role `orm:"reverse(many)"`

}

//用户表
func (u *User) TableName() string {
     return "sys_user"
}

//角色表
func (r *Role) TableName() string {
	return "sys_role"
}

//角色表
func (r *Auth) TableName() string {
	return "sys_auth"
}

func init()  {
	orm.RegisterModel(
        new(User),
        new(Role),
		new(Auth),
	)
}